package component;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import util.HibernateUtil;

public class TestComponent {
	@Test
	public void testSave(){
		Session s =HibernateUtil.getSession();
		Transaction t =s.beginTransaction();
		Name name=new Name();
		name.setFirstName("Bill");
		name.setMiddleName("O");
		name.setLastName("Gates");
		Foreigner bill=new Foreigner();
		bill.setName(name);
		s.save(bill);
		t.commit();
	}
	
	@Test
	public void testRead(){
		Session s = HibernateUtil.getSession();
		s.beginTransaction();
		Foreigner f =(Foreigner) s.get(Foreigner.class, 1);
		System.out.println(f.getName().getFirstName());
	}
	
	@Test
	public void testUpdate(){
		Session s = HibernateUtil.getSession();
		Transaction t =s.beginTransaction();
		Foreigner f =(Foreigner) s.get(Foreigner.class, 1);
		f.getName().setFirstName("Tom");
		t.commit();
	}
}
